﻿using System.ServiceModel;
using System.Xml;
using PolePosition.v3.Common;
using ProjectCommon2.Wcf.Attributes;
using PolePosition.v3.EntityLibrary;
using PolePosition.v3.EntityFactory;
using System.Data;


namespace PolePosition.v3.WcfService
{
    [ServiceContract(Name = "Utility", Namespace = "PolePosition.v3.WcfService")]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = true)]
    [ProjectCommon2.Wcf.Behaviors.GetContextServiceBehavior()]
    public class Utility
    {
        #region Project Data for Grids
        
        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionGpsProjectPoleData(int projectId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionGpsProjectPoleData(projectId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionGpsProjectPoleExcelData(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionGpsProjectPoleExcelData(projectId, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionGpsProjectStructureData(int projectId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionGpsProjectStructureData(projectId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionInspectionProjectPoleData(int projectId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionInspectionProjectPoleData(projectId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionInspectionProjectPoleExcelData(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionInspectionProjectPoleExcelData(projectId, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionInspectionProjectStructureData(int projectId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionInspectionProjectStructureData(projectId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetDistributionInspectionProjectData(int projectId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetDistributionInspectionProjectData(projectId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetDistributionInspectionProjectExcelData(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetDistributionInspectionProjectExcelData(projectId, searchBy, searchBytext);
        }

        #endregion

        #region Asset Data for Grids

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionAssetData(int utilityId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionAssetData(utilityId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXmissionAssetExcelData(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetXmissionAssetExcelData(utilityId, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetDistributionAssetData(int utilityId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetDistributionAssetData(utilityId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetDistributionAssetExcelData(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetDistributionAssetExcelData(utilityId, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetMeterAssetData(int utilityId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetMeterAssetData(utilityId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetMeterAssetExcelData(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetMeterAssetExcelData(utilityId, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetTransformerAssetData(int utilityId, int? pageSize, int? pageNumber, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetTransformerAssetData(utilityId, pageSize, pageNumber, searchBy, searchBytext);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetTransformerAssetExcelData(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            return GridDataFactory.GetTransformerAssetExcelData(utilityId, searchBy, searchBytext);
        }

        #endregion

        #region Project Id List for visits to Assets Grids

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetDistributionInspectionToAssetData(int projectId, int? pageSize, int? pageNumber, int? feets)
        {
            return GridDataFactory.GetDistributionInspVisitToAssetData(projectId, pageSize, pageNumber, feets);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetDistributionMeterToAssetData(int projectId, int? pageSize, int? pageNumber, int? feets)
        {
            return GridDataFactory.GetDistributionMeterToAssetData(projectId, pageSize, pageNumber, feets);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXMissionInspectionToAssetData(int projectId, int? pageSize, int? pageNumber, int? feets)
        {
            return GridDataFactory.GetXMissionInspVisitToAssetData(projectId, pageSize, pageNumber, feets);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetXMissionVisitToAssetData(int projectId, int? pageSize, int? pageNumber, int? feets)
        {
            return GridDataFactory.GetXMissionVisitToAssetData(projectId, pageSize, pageNumber, feets);
        }


        #endregion

        #region Project KML for Grids

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetXmissionGpsProjectPoleKML(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetXmissionGpsProjectPoleIdList(projectId, searchBy, searchBytext);

            return KML.GetTransmissionGpsVisitsKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetXmissionGpsProjectStructureKML(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetXmissionGpsProjectStructureIdList(projectId, searchBy, searchBytext);

            return KML.GetTransmissionGpsVisitsKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetXmissionInspectionProjectPoleKML(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetXmissionInspectionProjectPoleIdList(projectId, searchBy, searchBytext);

            return KML.GetTransmissionInspectionVisitsKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetXmissionInspectionProjectStructureKML(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetXmissionInspectionProjectStructureIdList(projectId, searchBy, searchBytext);

            return KML.GetTransmissionInspectionVisitsKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetDistributionInspectionProjectKML(int projectId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetDistributionInspectionProjectIdList(projectId, searchBy, searchBytext);

            return KML.GetDistributionInspectionVisitsKMLString(_idList, null, null, null, null);
        }

        #endregion



        #region Asset KML for Grids

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string TestKml()
        {
            // TODO: delete after test complete
            System.Data.SqlClient.SqlCommand _SqlCommand;
            _SqlCommand = new System.Data.SqlClient.SqlCommand();
            _SqlCommand.CommandText = "up_KML";
            _SqlCommand.Parameters.AddWithValue("@TranmissionStructuresList", "1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452");
            _SqlCommand.Parameters.AddWithValue("@TranmissionStructuresText", "Key");
            return ProjectCommon2.Helpers.SqlHelper.ExecuteScalar<string>(_SqlCommand);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetXmissionAssetKML(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetXmissionAssetIdList(utilityId, searchBy, searchBytext);

            return KML.GetTransmissionStructuresKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetDistributionAssetKML(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetDistributionAssetIdList(utilityId, searchBy, searchBytext);

            return KML.GetDistributionPolesKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetMeterAssetKML(int utilityId, Common.Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetMeterAssetIdList(utilityId, searchBy, searchBytext);

            return KML.GetMetersKMLString(_idList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetTransformerAssetKML(int utilityId, Enumerations.GridSearchByTpes searchBy, string searchBytext)
        {
            string _idList;
            _idList = GridDataFactory.GetTransformerAssetIdList(utilityId, searchBy, searchBytext);

            return KML.GetTransformersKMLString(_idList, null, null, null);
        }

        #endregion



        #region Work Queue KML for Grids

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetWorkqueueKML(string transmissionInspectionVisitsList, string distributionInspectionVisitsList)
        {
            return KML.GetKMLString(null, null, null, null,
                   null, transmissionInspectionVisitsList, null,
                   distributionInspectionVisitsList, null);
        }
       
        #endregion

        #region Get Specific Data Xmission Inspection

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorInspVisitXmissionStructuresResultsXNoteEntity> GetXmissionInspectionProjectNotesForResult(int resultId)
        {
            VendorInspVisitXmissionStructuresResultsXNoteEntity _ResultNote;
            _ResultNote = new VendorInspVisitXmissionStructuresResultsXNoteEntity() 
            { 
                Vendor_InspVisit_XmissionStructures_ResultFk = resultId
            };

            return VendorInspVisitXmissionStructuresResultsXNoteFactory.GetCollection(_ResultNote);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorInspVisitXmissionStructuresImageEntity> GetXmissionInspectionProjectPoleImages(int poleId)
        {
            VendorInspVisitXmissionStructuresImageEntity _PoleImage;
            _PoleImage = new VendorInspVisitXmissionStructuresImageEntity()
            {
                Vendor_InspVisit_XMissionStructure_PoleFk = poleId
            };

            ProjectCommon2.Generics.EntityCollection<VendorInspVisitXmissionStructuresImageEntity> _Images;
            _Images = VendorInspVisitXmissionStructuresImageFactory.GetCollection(_PoleImage);
            
            //lets retrieve the actual images here


            
            return _Images;
        }

        #endregion

        #region Get Specific Data Xmission Gps

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorVisitXMissionStructuresImageEntity> GetXmissionGpsProjectPoleImages(int poleId)
        {
            VendorVisitXMissionStructuresImageEntity _PoleImage;
            _PoleImage = new VendorVisitXMissionStructuresImageEntity()
            {
                Vendor_Visit_XMissionStructures_PoleFK = poleId
            };

            ProjectCommon2.Generics.EntityCollection<VendorVisitXMissionStructuresImageEntity> _Images;
            _Images = VendorVisitXMissionStructuresImageFactory.GetCollection(_PoleImage);

            //lets retrieve the actual images here
            foreach (VendorVisitXMissionStructuresImageEntity _Image in _Images)
            {
                _Image.Image = GetImageAsByteArray(_Image.Filename);
            }

            return _Images;
        }

        #endregion

        #region Get Specific Data Distribution Inspection

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionResultEntity> GetDistributionInspectionProjectNotesForResult(int poleId)
        {
            VendorDistributionResultEntity _ResultNote;
            _ResultNote = new VendorDistributionResultEntity()
            {
                Vendor_Distribution_PoleFk = poleId
            };

            return VendorDistributionResultFactory.GetCollection(_ResultNote);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionNotesXMeterEntity> GetDistributionInspectionProjectNotesForMeter(int meterId)
        {
            VendorDistributionNotesXMeterEntity _ResultNote;
            _ResultNote = new VendorDistributionNotesXMeterEntity()
            {
                Vendor_Distribution_MeterFk = meterId
            };

            return VendorDistributionNotesXMeterFactory.GetCollection(_ResultNote);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionNotesXTransformerEntity> GetDistributionInspectionProjectNotesForTransformer(int transformerId)
        {
            VendorDistributionNotesXTransformerEntity _ResultNote;
            _ResultNote = new VendorDistributionNotesXTransformerEntity()
            {
                Vendor_Distribution_TransformerFk = transformerId
            };

            return VendorDistributionNotesXTransformerFactory.GetCollection(_ResultNote);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionNotesXSectionalizerEntity> GetDistributionInspectionProjectNotesForSectionalizer(int sectionalizerId)
        {
            VendorDistributionNotesXSectionalizerEntity _ResultNote;
            _ResultNote = new VendorDistributionNotesXSectionalizerEntity()
            {
                Vendor_Distribution_SectionalizerFk = sectionalizerId
            };

            return VendorDistributionNotesXSectionalizerFactory.GetCollection(_ResultNote);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionNotesXRecloserEntity> GetDistributionInspectionProjectNotesForRecloser(int recloserId)
        {
            VendorDistributionNotesXRecloserEntity _ResultNote;
            _ResultNote = new VendorDistributionNotesXRecloserEntity()
            {
            Vendor_Distribution_RecloserFk = recloserId
            };

            return VendorDistributionNotesXRecloserFactory.GetCollection(_ResultNote);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionImageEntity> GetDistributionInspectionProjectPoleImages(int poleId)
        {
            VendorDistributionImageEntity _PoleImage;
            _PoleImage = new VendorDistributionImageEntity()
            {
                Vendor_Distribution_PoleFk = poleId
            };

            ProjectCommon2.Generics.EntityCollection<VendorDistributionImageEntity> _Images;
            _Images = VendorDistributionImageFactory.GetCollection(_PoleImage);

            //lets retrieve the actual images here
            foreach (VendorDistributionImageEntity _Image in _Images)
            {
                _Image.Image = GetImageAsByteArray(_Image.Filename);
            }

            return _Images;
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionTopsXPoleEntity> GetDistributionInspectionProjectTopsForPole(int poleId)
        {
            VendorDistributionTopsXPoleEntity _ResultTop;
            _ResultTop = new VendorDistributionTopsXPoleEntity()
            {
                Vendor_Distribution_PoleFk = poleId
            };

            return VendorDistributionTopsXPoleFactory.GetCollection(_ResultTop);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<VendorDistributionPhasesXPoleEntity> GetDistributionInspectionProjectPhasesForPole(int poleId)
        {
            VendorDistributionPhasesXPoleEntity _ResultPhase;
            _ResultPhase = new VendorDistributionPhasesXPoleEntity()
            {
                Vendor_Distribution_PoleFk = poleId
            };

            return VendorDistributionPhasesXPoleFactory.GetCollection(_ResultPhase);
        }

        #endregion

        #region Get Specific Data Xmission Structures

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<UtilityAssetXMissionStructuresImageEntity> GetXmissionAssetPoleImages(int poleId)
        {
            UtilityAssetXMissionStructuresImageEntity _PoleImage;
            _PoleImage = new UtilityAssetXMissionStructuresImageEntity()
            {
                Utility_Asset_XMissionStructures_PoleFK = poleId
            };

            ProjectCommon2.Generics.EntityCollection<UtilityAssetXMissionStructuresImageEntity> _Images;
            _Images = UtilityAssetXMissionStructuresImageFactory.GetCollection(_PoleImage);

            //lets retrieve the actual images here
            foreach (UtilityAssetXMissionStructuresImageEntity _Image in _Images)
            {
                _Image.Image = GetImageAsByteArray(_Image.Filename);
            }

            return _Images;
        }

        #endregion

        #region Get Specific Data Distribution Assets

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<UtilityAssetDistributionsImageEntity> GetDistributionAssetPoleImages(int poleId)
        {
            UtilityAssetDistributionsImageEntity _PoleImage;
            _PoleImage = new UtilityAssetDistributionsImageEntity()
            {
                Utility_Asset_DistributionFK = poleId
            };

            ProjectCommon2.Generics.EntityCollection<UtilityAssetDistributionsImageEntity> _Images;
            _Images = UtilityAssetDistributionsImageFactory.GetCollection(_PoleImage);

            //lets retrieve the actual images here
            foreach (UtilityAssetDistributionsImageEntity _Image in _Images)
            {
                _Image.Image = GetImageAsByteArray(_Image.Filename);
            }

            return _Images;
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public ProjectCommon2.Generics.EntityCollection<UtilityAssetMetersImageEntity> GetMeterAssetImages(int meterId)
        {
            UtilityAssetMetersImageEntity _PoleImage;
            _PoleImage = new UtilityAssetMetersImageEntity()
            {
                Utility_Asset_MeterFK = meterId
            };

            ProjectCommon2.Generics.EntityCollection<UtilityAssetMetersImageEntity> _Images;
            _Images = UtilityAssetMetersImageFactory.GetCollection(_PoleImage);

            //lets retrieve the actual images here
            foreach (UtilityAssetMetersImageEntity _Image in _Images)
            {
                _Image.Image = GetImageAsByteArray(_Image.Filename);
            }

            return _Images;
        }

        #endregion

        #region QuickSearch

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string QuickSearch(int? utilityId, string value, Enumerations.DataTypes type)
        {
            string _result = string.Empty;
            string searchedValue = string.Empty;
            int poleId;

            switch (type)
            {
                case Enumerations.DataTypes.ProjectsDistributionInspection:
                    if (int.TryParse(value, out poleId))
                        searchedValue = QuickSearchFactory.DistributionInspVisitQuickSearch(utilityId, poleId);

                    if (!string.IsNullOrEmpty(searchedValue))
                        _result = KML.GetDistributionInspectionVisitsKMLString(searchedValue, null, null, null, null);
                    break;

                case Enumerations.DataTypes.ProjectsXmissionInspection :
                    if (int.TryParse(value, out poleId))
                        searchedValue = QuickSearchFactory.XMissionInspVisitQuickSearch(utilityId, poleId);

                    if (!string.IsNullOrEmpty(searchedValue))
                        _result = KML.GetTransmissionInspectionVisitsKMLString(searchedValue, null, null, null, null);
                    break;

                case Enumerations.DataTypes.AssetsMeters:
                    searchedValue = QuickSearchFactory.AssetMeterQuickSearch(utilityId, value);

                    if (!string.IsNullOrEmpty(searchedValue))
                        _result = KML.GetMetersKMLString(searchedValue, null, null, null, null);

                    break;

                case Enumerations.DataTypes.AssetsDistribution:
                    if (int.TryParse(value, out poleId))
                        searchedValue = QuickSearchFactory.AssetDistributionQuickSearch(utilityId, poleId);

                    if (!string.IsNullOrEmpty(searchedValue))
                        _result = KML.GetDistributionPolesKMLString(searchedValue, null, null, null, null);

                    break;

                case Enumerations.DataTypes.AssetsXmission:
                    if (int.TryParse(value, out poleId))
                        searchedValue = QuickSearchFactory.AssetXMissionQuickSearch(utilityId, poleId);

                    if (!string.IsNullOrEmpty(searchedValue))
                        _result = KML.GetTransmissionStructuresKMLString(searchedValue, null, null, null, null);

                    break;
            }

            return _result;
        }

        #endregion

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public DataSet GetWorkQueueData(int utilityId)
        {
            return GridDataFactory.GetWorkQueueData(utilityId);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetUtilityKmlString(int? utilityId, int? userId)
        {
            return KMLFactory.GetUtilityKMLString(utilityId, userId);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetMapSearchCriteriaKMLString(
            string xMissionText, string distributionText,
            string xMissionGpsProjectList, string xMissionInspectionProjectList, 
            string distributionInspectionProjectList, string distributionGpsProjectList,
            bool? xMissionAssets, bool? distributionAssets, bool? meterAssets, bool? transformerAssets, int? utilityFk,
            string mapList, string sectionList, string xMissionKvList, string xMissionTopsList, 
            string xMissionSpeciesList, string xMissionTreatmentList, 
            string xMissionClassList, string xMissionAgeList, 
            string distributionPhaseList, string distributionTopsList, 
            string distributionSpeciesList, string distributionTreatmentList, 
            string distributionClassList, string distributionAgeList, 
            string meterNotesList, bool? electicalProblem, 
            string inspectionResultList, string inspectionTypeList, 
            string inspectionVendorList, string inspectionCompanyList, string inspectionNoteList)
        {
            return KMLFactory.GetMapSearchCriteriaKMLString(
                xMissionText, distributionText,
                xMissionGpsProjectList, xMissionInspectionProjectList, 
                distributionInspectionProjectList, distributionGpsProjectList, 
                xMissionAssets, distributionAssets, meterAssets, transformerAssets, utilityFk, 
                mapList, sectionList, xMissionKvList, xMissionTopsList, xMissionSpeciesList, 
                xMissionTreatmentList, xMissionClassList, xMissionAgeList, 
                distributionPhaseList, distributionTopsList, distributionSpeciesList, 
                distributionTreatmentList, distributionClassList, distributionAgeList, 
                meterNotesList, electicalProblem, inspectionResultList, inspectionTypeList, 
                inspectionVendorList, inspectionCompanyList, inspectionNoteList);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public int[] ValidateDistributionAssetId(int utilityId, int[] ids)
        {
            return UtilityAssetDistributionFactory.ValidateDistributionAssetId(utilityId, ids);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public int[] ValidateMeterAssetId(int utilityId, int[] ids)
        {
            return UtilityAssetDistributionFactory.ValidateMeterAssetId(utilityId, ids);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public int[] ValidateInspectionAssetId(int utilityId, int[] ids)
        {
            return UtilityAssetDistributionFactory.ValidateInspectionAssetId(utilityId, ids);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public void UpdateParentsByXml(string xml)
        {
            UtilityAssetDistributionFactory.UpdateParentsByXml(xml);
        }

        [OperationContract]
        public void CreateDistributionAssetsFromInspectionVisits(int ? vendorProjectId, XmlElement xml)
        {
            UtilityAssetDistributionFactory.CreateAssetsByInspectionXml(vendorProjectId, xml);
        }

        [OperationContract]
        public void CreateDistributionAssetsFromMeterVisits(int ? vendorProjectId, XmlElement xml)
        {
            UtilityAssetDistributionFactory.CreateAssetsByMeterXml(vendorProjectId, xml);
        }

        [OperationContract]
        public void CreateXMissionAssetsFromInspection(int? vendorProjectId, XmlElement xml)
        {
            UtilityAssetXMissionStructuresPoleFactory.CreateAssetsByInspectionXml(vendorProjectId, xml);
        }

        [OperationContract]
        public void CreateXMissionAssetsFromVisits(int? vendorProjectId, XmlElement xml)
        {
            UtilityAssetXMissionStructuresPoleFactory.CreateAssetsByVisitXml(vendorProjectId, xml);
        }

        private byte[] GetImageAsByteArray(string fileName)
        {
            //TODO: Write this method
            return null;
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetDistributionMetersAssetKmlString(string meterIdList)
        {
            return KML.GetMetersKMLString(meterIdList, null, null, null, null);
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public string GetDistributionTransformerssAssetKmlString(string transformerIdList)
        {
            return KML.GetTransformersKMLString(transformerIdList, null, null, null);
        }

        #region Various Save Methods

        #region Work Queue
        
        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public EntityLibrary.UtilityAssetXMissionStructurePolesCrossRemedyVendorInspectionVisitEntity SaveXmissionWorkqueue(EntityLibrary.UtilityAssetXMissionStructurePolesCrossRemedyVendorInspectionVisitEntity remedy)
        {
            EntityFactory.UtilityAssetXMissionStructurePolesCrossRemedyVendorInspectionVisitFactory.Save(remedy);
            return remedy;
        }

        [OperationContract]
        [MaxDataContractSerializerOperationBehavior]
        public EntityLibrary.VendorDistributionPoleRemedyEntity SaveDistributionWorkqueue(EntityLibrary.VendorDistributionPoleRemedyEntity remedy)
        {
            EntityFactory.VendorDistributionPoleRemedyFactory.Save(remedy);
            return remedy;
        }

        //[OperationContract]
        //[MaxDataContractSerializerOperationBehavior]
        //public EntityLibrary. SaveMeterWorkqueue(EntityLibrary. remedy)
        //{


        //}

        #endregion

        #region Assets
        
        #endregion

        #region Visits (Inspection/Gps)

        #endregion

        #endregion

    }
}
